package com.haier.npt.demo.api;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.haier.npt.common.JsonResult;
import com.haier.npt.constant.IConstInfo;
import com.haier.npt.demo.domain.Demo;
import com.haier.npt.demo.i18n.DemoExceptionCode;
import com.haier.npt.demo.i18n.DemoMessageCode;
import com.haier.npt.demo.resource.DemoResource;
import com.haier.npt.demo.service.DemoService;
import com.haier.npt.exception.BizBaseException;
import com.haier.npt.page.PageBean;
import com.haier.npt.sso.domain.HaierUser;
import com.haier.npt.utils.MessageHelper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lixu
 * @since 2018-07-17
 */
@Api("Demo接口")
@RestController
@RequestMapping("/internal/demo")
public class DemoApi implements DemoResource{
	
	@Autowired
	private DemoService service;
	
    @Autowired
    private MessageHelper messageHelper;

	@Override
	public JsonResult<Object> getDemoList() {
		return JsonResult.success(service.selectList(new EntityWrapper<Demo>()));
	}
	
	@ApiOperation(value="获取用户列表", notes="获取用户列表")
	@RequestMapping(value="/page",method=RequestMethod.GET)
	public JsonResult<PageBean<Demo>> getDemoPageList(
			                          @RequestParam(value = "currentPage", required = false, defaultValue = IConstInfo.DEFAULT_CURRENT_PAGE) Integer currentPage,
			                          @RequestParam(value = "pageSize", required = false, defaultValue = IConstInfo.DEFAULT_PAGESIZE) Integer pageSize){
		Page<Demo> page = new Page<>(currentPage,pageSize);
		String ms = messageHelper.getMessage(DemoMessageCode.TEST);
		System.out.println(ms);
		if(1==1){
			throw new BizBaseException(DemoExceptionCode.TEST);
		}
		service.getDemoList(page);
		return JsonResult.success(PageBean.toPageBean(page));
	}
	
	@ApiOperation(value="模拟假数据", notes="模拟假数据")
    @RequestMapping(value = "/jData",method=RequestMethod.GET)
    public HaierUser jData(@RequestHeader("Authorization") String Authorization){
		HaierUser sysUser = new HaierUser();
		sysUser.setId(111111111L); // 全局id
		sysUser.setMobile("18705423322"); // 手机
		sysUser.setEmail("lixu.dts@qq.com"); // 邮箱
		sysUser.setNickName("李旭");//// 用户昵称，用于展示
		sysUser.setExtUserData("");
		sysUser.setUserName("李旭");
		sysUser.setAccessToken(Authorization.split(" ")[1]);
		sysUser.setLastLoginDate(new Date());
		sysUser.setSystem(false);
		sysUser.setRegisteDate(new Date());
		sysUser.setCreatedate(new Date());
		return sysUser;
    }
}
